package aiku.numericalcontroloa.Controller.Devices;

import aiku.numericalcontroloa.Base.Utils.Result;
import aiku.numericalcontroloa.Model.Dto.DevicesDto;
import aiku.numericalcontroloa.Model.Dto.DevicesPartVo;
import aiku.numericalcontroloa.Model.Entity.Devices;
import aiku.numericalcontroloa.Service.Impl.DevicesServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * @author 马文杰
 * @version 1.0
 */
@RestController
@RequestMapping("/devices")
public class DevicesController {
    @Autowired
    private DevicesServiceImpl devicesService;
    //通过名称查询仓库已存在的商品信息返回
    @PostMapping("/selectName")
    public Result selectName(@RequestParam("name") String name){
        return devicesService.selectName(name);
    }
    /**
     * 查询仓库已存在的商品信息返回
     * @param page
     */
    @PostMapping("/selectList")
    public Result selectList(@RequestParam("page") Integer page, @RequestParam("size") Integer size, @RequestParam("status") String status){
        return devicesService.selectList(page, size,status);
    }

    /**
     * 查询仓库所有配件
     */
    @PostMapping("/selectPartList")
    public Result selectPartList(){
        return devicesService.selectPartList();
    }

    /**
     * 通过名称,型号搜索仓库零件信息
     */
    @PostMapping("/selectPartLike")
    public Result selectPartLike(@RequestParam("name") String name){
        return devicesService.selectPartLike(name);
    }


    /**
     * 通过模糊查询仓库已存在的商品信息返回
     */
    @PostMapping("/selectLike")
    public Result selectLike(@RequestParam("name") String name){
        return devicesService.selectLike(name);
    }

    /**
     * 在仓库新增产品，而不是零件，产品由零件组成
     */
    @PostMapping("/addProductIs")
    public Result addProductIs(@RequestBody DevicesPartVo devices){
        return devicesService.addProductIs(devices);
    }

    /**
     * 查询百分比
     */
    @PostMapping("/selectPercent")
    public Result selectPercent(){
        return devicesService.selectPercent();
    }

    /**
     * 修改百分比
     */
    @PostMapping("/updatePercent")
    public Result updatePercent(@RequestParam("percent") Integer percent){
        return devicesService.updatePercent(percent);
    }

    /**
     * 管理员修改库存信息
     */
    @PostMapping("/adminUpdateDevice")
    public Result adminUpdateDevice(@RequestBody Devices devices){
        return devicesService.adminUpdateDevice(devices);
    }

    /**
     * 出入库分页报表展示
     */
    @PostMapping("/selectOutboundList")
    public Result selectOutboundList(@RequestParam("page") Integer page, @RequestParam("size") Integer size){
        return devicesService.selectOutboundList(page, size);
    }

    /**
     * 通过产品名称,型号模糊查询出入库报表展示
     */
    @PostMapping("/selectOutboundLike")
    public Result selectOutboundLike(@RequestParam("name") String name){
        return devicesService.selectOutboundLike(name);
    }

    /**
     * 获取产品列表
     * 可根据产品名称或型号模糊查询
     * 可根据产品类型查询，0成品，1零件
     * @param devicesDto
     * @return
     */
    @PostMapping("/getDeviceList")
    public Result getDeviceList(@RequestBody DevicesDto devicesDto){
        return devicesService.getDeviceList(devicesDto);
    }

    /**
     * 查单个产品
     * @param devicesDto
     * @return
     */
    @PostMapping("/getDevice")
    public Result getDevice(@RequestBody DevicesDto devicesDto){
        return devicesService.getDevice(devicesDto);
    }

    /**
     * 添加产品
     * @param devicesDto
     * @return
     */
    @PostMapping("/addDevice")
    public Result addDevice(@RequestBody DevicesDto devicesDto){
        return devicesService.addDevice(devicesDto);
    }

    /**
     * 修改产品
     * @param devicesDto
     * @return
     */
    @PostMapping("/updateDevice")
    public Result updateDevice(@RequestBody DevicesDto devicesDto){
        return devicesService.updateDevice(devicesDto);
    }

    /**
     * 删除产品
     * @param devicesDto
     * @return
     */
    @PostMapping("/deleteDevice")
    public Result deleteDevice(@RequestBody DevicesDto devicesDto){
        return devicesService.deleteDevice(devicesDto);
    }

    /**
     * 组装成品
     * @param devicesDto
     * @return
     */
    @PostMapping("/assembleDevice")
    public Result assembleDevice(@RequestBody DevicesDto devicesDto) {
        return devicesService.assembleDevice(devicesDto);
    }

    /**
     * 拆解成品
     * @param devicesDto
     * @return
     */
    @PostMapping("/dismantleDevice")
    public Result dismantleDevice(@RequestBody DevicesDto devicesDto){
        return devicesService.dismantleDevice(devicesDto);
    }

    /**
     * 计算组装成品
     * @return
     */
    @PostMapping("/calculateAssembleDevice")
    public Result calculateAssembleDevice(){
        return devicesService.calculateAssembleDevice();
    }

    @PostMapping("/changeDeviceImg")
    public Result changeDeviceImg(@RequestBody DevicesDto devicesDto){
        return devicesService.changeDeviceImg(devicesDto);
    }
}
